<%@ page contentType="text/html;charset=utf-8" language="java"
	pageEncoding="UTF-8" import="java.util.Date"%>
<%@include file="../common/mastertopedit.jsp"%>
<div class="form-horizontal pt-15  form-clean-magin">
	<div class="form-group">
			<label class="col-xs-3 text-right control-label usual-label">模板下载</label>
			<div class="col-xs-9">
				
				<div class="pull-left up-file pt-7">
					<a href="../../template/门店商品导入.xlsx" id="testload">门店商品导入模板.xlsx</a>
				</div>
			</div>
		</div>
	<div class="form-group">
		<label class="col-xs-3 text-right control-label usual-label">文件上传</label>
		<div class="col-xs-9">
			<form enctype="multipart/form-data" method="post" name="uploadForm" id="uploadForm"> 
			<input type="hidden" name="fileFlag" value="1"/>
			<div class="pull-left up-file pt-7">
				<input type="file" multiple name="file"  onchange="doUpload()"/>
				<a href="javascript:downLoad()" class="text-line">上传</a>
			</div>
			<div class="pull-left up-file pt-7">
				<a href="" id="imagea"></a>
			</div>
			</form>
		</div>
	</div>
</div>

<div class="form-group text-center">
	<button type="button" class="runmi-btn runmi-primary"
		onclick="backIndex()">取消</button>
	<button type="button" class="runmi-btn runmi-sure-btn" onclick="save()">保存</button>
</div>

<script type="text/javascript">
	function downLoad(){
		
		//var url=$('#imagea').attr("url");
	//	var fileName=$('#imagea').attr("fileName");
		//var turl='${pageContext.request.contextPath}/common/file/download?url=' +encodeURIComponent(url) + "&fileName=" + encodeURIComponent(fileName);
		//window.location.href=turl;
	}
	function doUpload() {  
		var domainUrl="${pageContext.request.contextPath}/admin/setupitem/importfile";
		 layer.load(1, {shade: [0.5,'#fff']});
	     var formData = new FormData($("#uploadForm")[0]);   
	     $.ajax({   
	          url: domainUrl,   
	          type: 'POST',   
	          data: formData,   
	          async: false,   
	          cache: false,   
	          contentType: false,   
	          processData: false,   
	          success: function (resultdata) {   
	        	  layer.closeAll();
	        	  //alert(resultdata.returnCode);
	              if(resultdata.returnCode=="0000"){               	
	            	  layer.alert('操作成功', {
							icon : 1
						}, function() {
							parent.oksubmit();
						});
	         
	              }else{
	              	layer.alert(resultdata.returnMessage);
	              }
	          },   
	          error: function (returndata) {  
	        	  alert('error')
	        	  layer.closeAll();
	        	  alert(returndata);
	          }   
	     });   
	} 
	</script>

<script type="text/javascript">
  function save(){	  
  		var randId=$('#imagea').attr("randId");	
		var postData="randId=" +randId ;
		
		
	    layer.load(1, {shade: [0.5,'#fff']});
	    //alert(postData);
	    $.ajax({
	        type: "POST",
	        url: "initimport",
	        data: postData,
	        contentType: "application/x-www-form-urlencoded;charset=UTF-8",
	        async: true, // 同步  true 异步。默认是异步
	        dataType: 'json',
	        error: function(resultdata) {
	        	layer.closeAll();
	        },
	        success: function(resultdata) {
	        	layer.closeAll();
	            if(resultdata.returnCode=="0000"){
	            	alert(resultdata.data);
	            	layer.alert(resultdata.data,{icon: 1}, function(){
	            	 	 parent.editReturn();
	            	});
	            }else{
	            	layer.alert(resultdata.returnMessage);
	            }
	        }
	    });
	}
  function backIndex(){	  
 	 parent.editReturn();
  }
	</script>
<%@include file="../common/masterbottom.jsp"%>
